package com.rj.framework.component.interceptor.impl;

import com.rj.framework.component.BusinessComponent;
import com.rj.framework.component.interceptor.ComponentInterceptor;
import com.rj.framework.context.Context;
import lombok.extern.slf4j.Slf4j;

/**
 * 日志处理
 *
 * @author YFX_RANLUBO
 * @date 2025/06/27 11:05
 **/
@Slf4j
public class LogComponentInterceptor implements ComponentInterceptor {

    @Override
    public <I, O, C extends Context<?>> BusinessComponent<I, O, C> intercept(BusinessComponent<I, O, C> component, String componentName) {
        return ((input, context) -> {
            O result = null;
            try {
                result = component.execute(input, context);
                return result;
            } catch (Exception e) {
                throw e;
            } finally {
                log.info("\n组件: {},输入参数: {} 输出结果: {}", componentName, input, result);
            }
        });
    }
}
